from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-13 14:06:19.166560
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 13, Feb, 2021
Time: 14:06:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1142
Nobs: 201.000 HQIC: -46.9948
Log likelihood: 2306.26 FPE: 2.14204e-21
AIC: -47.5933 Det(Omega_mle): 1.38372e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.466845 0.140138 3.331 0.001
L1.Burgenland 0.081995 0.072079 1.138 0.255
L1.Kärnten -0.217904 0.060798 -3.584 0.000
L1.Niederösterreich 0.125242 0.167256 0.749 0.454
L1.Oberösterreich 0.241201 0.147273 1.638 0.101
L1.Salzburg 0.202420 0.077596 2.609 0.009
L1.Steiermark 0.102633 0.104560 0.982 0.326
L1.Tirol 0.147847 0.070053 2.111 0.035
L1.Vorarlberg -0.004510 0.064283 -0.070 0.944
L1.Wien -0.131748 0.138299 -0.953 0.341
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.482515 0.169919 2.840 0.005
L1.Burgenland 0.012039 0.087397 0.138 0.890
L1.Kärnten 0.358286 0.073718 4.860 0.000
L1.Niederösterreich 0.127817 0.202801 0.630 0.529
L1.Oberösterreich -0.138315 0.178571 -0.775 0.439
L1.Salzburg 0.199574 0.094086 2.121 0.034
L1.Steiermark 0.208047 0.126781 1.641 0.101
L1.Tirol 0.137983 0.084940 1.624 0.104
L1.Vorarlberg 0.168244 0.077944 2.159 0.031
L1.Wien -0.543670 0.167690 -3.242 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.315321 0.062469 5.048 0.000
L1.Burgenland 0.107267 0.032131 3.338 0.001
L1.Kärnten -0.018709 0.027102 -0.690 0.490
L1.Niederösterreich 0.079924 0.074558 1.072 0.284
L1.Oberösterreich 0.290335 0.065650 4.422 0.000
L1.Salzburg -0.003463 0.034590 -0.100 0.920
L1.Steiermark -0.017659 0.046610 -0.379 0.705
L1.Tirol 0.086526 0.031227 2.771 0.006
L1.Vorarlberg 0.110549 0.028655 3.858 0.000
L1.Wien 0.055942 0.061649 0.907 0.364
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.224272 0.070275 3.191 0.001
L1.Burgenland -0.009447 0.036146 -0.261 0.794
L1.Kärnten 0.024142 0.030488 0.792 0.428
L1.Niederösterreich 0.050431 0.083875 0.601 0.548
L1.Oberösterreich 0.381232 0.073854 5.162 0.000
L1.Salzburg 0.091917 0.038912 2.362 0.018
L1.Steiermark 0.182013 0.052434 3.471 0.001
L1.Tirol 0.040417 0.035130 1.151 0.250
L1.Vorarlberg 0.091328 0.032236 2.833 0.005
L1.Wien -0.078520 0.069353 -1.132 0.258
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.519753 0.140655 3.695 0.000
L1.Burgenland 0.056007 0.072346 0.774 0.439
L1.Kärnten 0.014380 0.061022 0.236 0.814
L1.Niederösterreich -0.033178 0.167874 -0.198 0.843
L1.Oberösterreich 0.150596 0.147817 1.019 0.308
L1.Salzburg 0.061359 0.077883 0.788 0.431
L1.Steiermark 0.126556 0.104947 1.206 0.228
L1.Tirol 0.212235 0.070311 3.019 0.003
L1.Vorarlberg 0.027699 0.064521 0.429 0.668
L1.Wien -0.125543 0.138810 -0.904 0.366
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165025 0.099231 1.663 0.096
L1.Burgenland -0.016281 0.051039 -0.319 0.750
L1.Kärnten -0.009242 0.043051 -0.215 0.830
L1.Niederösterreich 0.116808 0.118434 0.986 0.324
L1.Oberösterreich 0.389429 0.104284 3.734 0.000
L1.Salzburg -0.021216 0.054946 -0.386 0.699
L1.Steiermark -0.023182 0.074039 -0.313 0.754
L1.Tirol 0.191051 0.049604 3.852 0.000
L1.Vorarlberg 0.040224 0.045519 0.884 0.377
L1.Wien 0.174407 0.097929 1.781 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231342 0.127441 1.815 0.069
L1.Burgenland 0.063192 0.065549 0.964 0.335
L1.Kärnten -0.039369 0.055289 -0.712 0.476
L1.Niederösterreich -0.026877 0.152103 -0.177 0.860
L1.Oberösterreich -0.091398 0.133930 -0.682 0.495
L1.Salzburg 0.037571 0.070566 0.532 0.594
L1.Steiermark 0.390764 0.095087 4.110 0.000
L1.Tirol 0.489048 0.063706 7.677 0.000
L1.Vorarlberg 0.165111 0.058459 2.824 0.005
L1.Wien -0.217960 0.125769 -1.733 0.083
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079372 0.153640 0.517 0.605
L1.Burgenland 0.033174 0.079024 0.420 0.675
L1.Kärnten -0.083250 0.066655 -1.249 0.212
L1.Niederösterreich 0.247815 0.183371 1.351 0.177
L1.Oberösterreich -0.007915 0.161463 -0.049 0.961
L1.Salzburg 0.233081 0.085072 2.740 0.006
L1.Steiermark 0.140847 0.114635 1.229 0.219
L1.Tirol 0.070947 0.076802 0.924 0.356
L1.Vorarlberg 0.051670 0.070477 0.733 0.463
L1.Wien 0.239342 0.151624 1.579 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588129 0.082953 7.090 0.000
L1.Burgenland -0.033126 0.042667 -0.776 0.438
L1.Kärnten -0.010865 0.035989 -0.302 0.763
L1.Niederösterreich -0.022977 0.099006 -0.232 0.816
L1.Oberösterreich 0.293733 0.087177 3.369 0.001
L1.Salzburg 0.018772 0.045932 0.409 0.683
L1.Steiermark 0.003143 0.061894 0.051 0.960
L1.Tirol 0.077001 0.041467 1.857 0.063
L1.Vorarlberg 0.128897 0.038052 3.387 0.001
L1.Wien -0.036813 0.081865 -0.450 0.653
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137724 0.034833 0.198324 0.256194 0.062993 0.096246 -0.056700 0.166774
Kärnten 0.137724 1.000000 0.010475 0.189028 0.165678 -0.117648 0.155930 0.010208 0.320662
Niederösterreich 0.034833 0.010475 1.000000 0.312239 0.083265 0.216854 0.129816 0.051587 0.362742
Oberösterreich 0.198324 0.189028 0.312239 1.000000 0.297601 0.295404 0.108332 0.079836 0.134305
Salzburg 0.256194 0.165678 0.083265 0.297601 1.000000 0.149191 0.063455 0.086349 -0.005301
Steiermark 0.062993 -0.117648 0.216854 0.295404 0.149191 1.000000 0.103220 0.099258 -0.101365
Tirol 0.096246 0.155930 0.129816 0.108332 0.063455 0.103220 1.000000 0.158168 0.159547
Vorarlberg -0.056700 0.010208 0.051587 0.079836 0.086349 0.099258 0.158168 1.000000 0.048159
Wien 0.166774 0.320662 0.362742 0.134305 -0.005301 -0.101365 0.159547 0.048159 1.000000